package com.lvy.hczn.front.business.controller;

import com.lvy.hczn.front.business.common.Constants;
import com.lvy.hczn.front.business.dto.Param;
import com.lvy.hczn.front.business.service.SpuSortRecordService;
import com.lvy.hczn.front.business.util.ResultUtil;
import com.lvy.hczn.front.common.core.controller.BaseController;
import com.lvy.hczn.front.common.exception.UtilException;
import com.lvy.hczn.front.system.domain.business.GoodsBox;
import com.lvy.hczn.front.system.domain.business.SpuSortRecord;
import com.lvy.hczn.mq.rocket.ParamInfo;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/wcs/record")
@RestController
@Slf4j
public class SpuSortRecordController extends BaseController {

    @Autowired
    private SpuSortRecordService spuSortRecordService;

    @ApiOperation(value = "货箱临期列表", notes = "货箱临期列表")
    @PostMapping("/untreated/list")
    public ResultUtil untreatedList(@RequestBody ParamInfo paramInfo) {
        try {
            List<SpuSortRecord> list = spuSortRecordService.untreatedList(paramInfo);
            return ResultUtil.ok(list);
        } catch (Exception e) {
            log.error("sortBySpu:", e);
            if (e instanceof UtilException) {
                return ResultUtil.failed(e.getMessage());
            } else {
                log.error("货箱临期列表：", e);
                return ResultUtil.failed("系统异常");
            }
        }
    }

    @ApiOperation(value = "货箱临期首页统计", notes = "货箱临期首页统计")
    @PostMapping("/untreated/count")
    public ResultUtil untreatedCount(@RequestBody ParamInfo paramInfo) {
        try {
            return ResultUtil.ok(spuSortRecordService.untreatedCount(paramInfo));
        } catch (Exception e) {
            log.error("sortBySpu:", e);
            if (e instanceof UtilException) {
                return ResultUtil.failed(e.getMessage());
            } else {
                log.error("货箱临期列表：", e);
                return ResultUtil.failed("系统异常");
            }
        }
    }

    @ApiOperation(value = "平台临期报损出库", notes = "平台临期报损出库")
    @PostMapping("/frm/loss")
    public ResultUtil frmLoss(@RequestBody ParamInfo paramInfo) {
        try {
            spuSortRecordService.frmLoss(paramInfo);
            return ResultUtil.ok();
        } catch (Exception e) {
            log.error("frmLoss:", e);
            if (e instanceof UtilException) {
                return ResultUtil.failed(e.getMessage());
            } else {
                log.error("平台临期报损出库：", e);
                return ResultUtil.failed("系统异常");
            }
        }
    }

    @ApiOperation(value = "仓库报损", notes = "退货入库报损,直接报损，不更新到平台")
    @PostMapping("/frm/loss/done")
    public ResultUtil frmLossDone(@RequestBody ParamInfo paramInfo) {
        try {
            spuSortRecordService.frmLossDone(paramInfo);
            return ResultUtil.ok();
        } catch (Exception e) {
            log.error("frmLoss:", e);
            if (e instanceof UtilException) {
                return ResultUtil.failed(e.getMessage());
            } else {
                log.error("仓库报损异常：", e);
                return ResultUtil.failed("系统异常");
            }
        }
    }
}
